#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>

struct list {
    int num;
    struct list* next;
};
#define LEN sizeof(struct list)

struct list* creat(int n) {
    int tmp = n;
    struct list* head = NULL, * p1, * p2;

    p1 = (struct list*)malloc(LEN);
    scanf_s("%d", &p1->num);
    head = p1;
    p2 = p1;

    while (--n > 0) {
        p1 = (struct list*)malloc(LEN);
        scanf_s("%d", &p1->num);
        p2->next = p1;
        p2 = p1;
    }
    p2->next = NULL;
    return head;
}

void bijiao(struct list* h) {
    int pos1 = 0, pos2 = 0, max, min, index = 0;
    struct list* p = h;

    max = min = p->num;  // Set initial max and min to the first element
    while (p != NULL) {
        if (p->num > max) {
            max = p->num;
            pos1 = index;
        }
        if (p->num < min) {
            min = p->num;
            pos2 = index;
        }
        p = p->next;
        index++;
    }

    // Display the max and min values and their positions
    printf("max=%d, pos1=%d\n", max, pos1);
    printf("min=%d, pos2=%d\n", min, pos2);

    // Visualization using EasyX
    initgraph(640, 480); // Initialize the graphical window

    p = h;
    int x = 50, y = 100; // Starting position for drawing the list
    index = 0;

    while (p != NULL) {
        // Draw the rectangle for each node
        if (index == pos1) {  // Highlight max node
            setfillcolor(RED);
            solidrectangle(x, y, x + 50, y + 30);
        }
        else if (index == pos2) {  // Highlight min node
            setfillcolor(BLUE);
            solidrectangle(x, y, x + 50, y + 30);
        }
        else {
            setfillcolor(GREEN);
            solidrectangle(x, y, x + 50, y + 30);
        }

        // Draw the number in the rectangle 
        settextcolor(WHITE);
        settextstyle(20, 0, _T("Arial"));
        outtextxy(x + 10, y + 5, _T(" %d ", p->num));
        // Draw the arrow pointing to the next node 
        if (p->next != NULL) {
            setcolor(WHITE);
            line(x + 50, y + 15, x + 100, y + 15); // Draw arrow 
        }
        p = p->next;
        x += 100; // Move to the right for the next node 
        index++;
    }
    // Wait for the user to close the window 
    closegraph();
}
int main() {
    int n;
    scanf_s("%d", &n);
    struct list* head = NULL;
    head = creat(n);
    bijiao(head);
    return 0;
}